﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace CANO.Data.DAOs.Calendar
{
	public class DaySection
	{
		public string dayName { get; set; }
		public string dateDisplay { get; set; }
		public List<Event> events { get; set; }

		public List<DaySection> GetDaysSectionManager()
		{
			List<DaySection> ListDaySectionReturn = new List<DaySection>();

			List<Event> TotalEventsWeek = new Event().GetAllEvents();

			for (int i = 0; i < 7; i++)
			{
				DateTime currentDay = DateTime.Now.Date.AddDays(i);

				DaySection CurrentDaySection = new DaySection();

				CultureInfo ci = new CultureInfo("Es-Es");

				CurrentDaySection.dayName = ci.DateTimeFormat.GetDayName(currentDay.DayOfWeek).ToString();
				CurrentDaySection.dateDisplay = ci.DateTimeFormat.GetMonthName(currentDay.Month).ToString().ToUpper() + " " + currentDay.Day.ToString();
				CurrentDaySection.events = new List<Event>();

				foreach (var item in TotalEventsWeek)
				{
					if (item.dateTimeEvent.Date == currentDay.Date)
					{
						CurrentDaySection.events.Add(new CANO.Data.DAOs.Event
						{
							eventID = item.eventID,
							eventTypeDisplay = item.eventTypeDisplay,
							time = item.time,
							typeID = item.typeID,
							dateTimeEvent = item.dateTimeEvent,
							dateTimeEventShort = item.dateTimeEventShort,
							Users = item.Users,
							Contacts = item.Contacts
						});
					}
				}

				ListDaySectionReturn.Add(CurrentDaySection);
			}

			return ListDaySectionReturn;
		}

		internal List<DaySection> GetDaysSectionByUserID(int CurrentUserID)
		{
			List<DaySection> ListDaySectionReturn = new List<DaySection>();

			List<Event> TotalEventsWeek = new Event().GetEventsByUserID(CurrentUserID);

			for (int i = 0; i < 7; i++)
			{
				DateTime currentDay = DateTime.Now.Date.AddDays(i);

				DaySection CurrentDaySection = new DaySection();

				CultureInfo ci = new CultureInfo("Es-Es");

				CurrentDaySection.dayName = ci.DateTimeFormat.GetDayName(currentDay.DayOfWeek).ToString();
				CurrentDaySection.dateDisplay = ci.DateTimeFormat.GetMonthName(currentDay.Month).ToString().ToUpper() + " " + currentDay.Day.ToString();
				CurrentDaySection.events = new List<Event>();

				foreach (var item in TotalEventsWeek)
				{
					if (item.dateTimeEvent.Date == currentDay.Date)
					{
						CurrentDaySection.events.Add(new CANO.Data.DAOs.Event
						{
							eventID = item.eventID,
							eventTypeDisplay = item.eventTypeDisplay,
							time = item.time,
							typeID = item.typeID,
							dateTimeEvent = item.dateTimeEvent,
							dateTimeEventShort = item.dateTimeEventShort,
							Users = item.Users,
							Contacts = item.Contacts
						});
					}
				}

				ListDaySectionReturn.Add(CurrentDaySection);
			}
			return ListDaySectionReturn;
		}

	}
}
